﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Task;

namespace task
{
    public partial class FormInfomation : Form
    {
        public Material Material { get; set; }

        readonly bool _updateFlag = false;
        public FormInfomation()
        {
            InitializeComponent();
        }

        public FormInfomation(Material material,bool flag)
        {
            Material = material;
            InitializeComponent();
            txt_Name.Text = material.Name;
            txt_Type.Text = material.Type;
            txt_Subtype.Text = material.SubType;
            txt_Date.Text = material.Date;
            txt_Content.Text = material.Content;
            _updateFlag = flag;
            Init();
        }

        private void Init()
        {
            if (_updateFlag)
            {
                txt_Name.ReadOnly = false;
                txt_Content.ReadOnly = false;
                btn_Submit.Visible = true;
            }
        }

        private void Btn_Submit_Click(object sender, EventArgs e)
        {
            Material.Date = DateTime.Now.ToString();
            Material.Content = txt_Content.Text;
            Material.Name = txt_Name.Text;
            DbHandler.UpdateMaterial(Material);
            FormData.RefreshListFlag = true;
            MessageBox.Show("成功");
            Dispose();
        }
    }
}
